{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "f_dir = \"./small\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Dataset & #Seeds & Model & L & Param & Acc_test & Acc_train & Speed & Epoch/Time\n",
      "ZINC & 4 & MLP & 4 & 108975 & 0.706$\\pm$0.006 & 0.644$\\pm$0.005 & 116.75 & 1.01s/0.03hr\n",
      "\n",
      "Dataset & #Seeds & Model & L & Param & Acc_test & Acc_train & Speed & Epoch/Time\n",
      "ZINC & 4 & GCN & 4 & 103077 & 0.459$\\pm$0.006 & 0.343$\\pm$0.011 & 196.25 & 2.89s/0.16hr\n",
      "\n",
      "Dataset & #Seeds & Model & L & Param & Acc_test & Acc_train & Speed & Epoch/Time\n",
      "ZINC & 4 & GraphSage & 4 & 94977 & 0.468$\\pm$0.003 & 0.251$\\pm$0.004 & 147.25 & 3.74s/0.15hr\n",
      "\n",
      "Dataset & #Seeds & Model & L & Param & Acc_test & Acc_train & Speed & Epoch/Time\n",
      "ZINC & 4 & GatedGCN & 4 & 105735 & 0.435$\\pm$0.011 & 0.287$\\pm$0.014 & 173.50 & 5.76s/0.28hr\n",
      "\n",
      "Dataset & #Seeds & Model & L & Param & Acc_test & Acc_train & Speed & Epoch/Time\n",
      "ZINC & 4 & GAT & 4 & 102385 & 0.475$\\pm$0.007 & 0.317$\\pm$0.006 & 137.50 & 2.93s/0.11hr\n",
      "\n",
      "Dataset & #Seeds & Model & L & Param & Acc_test & Acc_train & Speed & Epoch/Time\n",
      "ZINC & 4 & MoNet & 4 & 106002 & 0.388$\\pm$0.008 & 0.295$\\pm$0.019 & 154.75 & 12.33s/0.54hr\n",
      "\n",
      "Dataset & #Seeds & Model & L & Param & Acc_test & Acc_train & Speed & Epoch/Time\n",
      "ZINC & 4 & GIN & 4 & 103079 & 0.387$\\pm$0.015 & 0.319$\\pm$0.015 & 153.25 & 2.29s/0.10hr\n",
      "\n",
      "Dataset & #Seeds & Model & L & Param & Acc_test & Acc_train & Speed & Epoch/Time\n",
      "ZINC & 4 & 3WLGNN & 3 & 102150 & 0.407$\\pm$0.028 & 0.272$\\pm$0.037 & 111.25 & 286.23s/8.88hr\n",
      "\n",
      "Dataset & #Seeds & Model & L & Param & Acc_test & Acc_train & Speed & Epoch/Time\n",
      "ZINC & 4 & RingGNN & 2 & 97978 & 0.512$\\pm$0.023 & 0.383$\\pm$0.020 & 90.25 & 327.65s/8.32hr\n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "file = []\n",
    "dataset = []\n",
    "model = []\n",
    "layer = []\n",
    "params = []\n",
    "acc_test = []\n",
    "acc_train = []\n",
    "convergence = []\n",
    "total_time = []\n",
    "epoch_time = []\n",
    "\n",
    "for filename in os.listdir(f_dir):\n",
    "\n",
    "    if filename[-4:] == \".txt\":\n",
    "        file.append( filename )\n",
    "        \n",
    "        with open(os.path.join(f_dir, filename), \"r\") as f:\n",
    "            lines = f.readlines()\n",
    "\n",
    "            for line in lines:\n",
    "                #print('h1c',line)\n",
    "\n",
    "                if line[:9] == \"Dataset: \":\n",
    "                    dataset.append( line[9:-2] )\n",
    "\n",
    "                if line[:7] == \"Model: \":\n",
    "                    model.append( line[7:-1] )\n",
    "\n",
    "                if line[:17] == \"net_params={'L': \":\n",
    "                    layer.append( line[17:18] )\n",
    "                    \n",
    "                if line[:18] == \"Total Parameters: \":\n",
    "                    params.append( line[18:-1] )\n",
    "\n",
    "                if line[:10] == \"TEST MAE: \":\n",
    "                    acc_test.append( float(line[10:-1]) )\n",
    "                \n",
    "                if line[:11] == \"TRAIN MAE: \":\n",
    "                    acc_train.append( float(line[11:-1]) )\n",
    "                \n",
    "                if line[4:31] == \"Convergence Time (Epochs): \":\n",
    "                    convergence.append( float(line[31:-1]) )\n",
    "\n",
    "                if line[:18] == \"Total Time Taken: \":\n",
    "                    total_time.append( float(line[18:-4]) )\n",
    "\n",
    "                if line[:24] == 'Average Time Per Epoch: ':\n",
    "                    epoch_time.append( float(line[24:-2]) )\n",
    "                    \n",
    "                    \n",
    "        \n",
    "        \n",
    "# print('file',file)\n",
    "# print('dataset',dataset)\n",
    "# print('model',model)\n",
    "# print('layer',layer)\n",
    "# print('params',params)\n",
    "# print('acc_test',acc_test)\n",
    "# print('acc_train',acc_train)\n",
    "# print('convergence',convergence)\n",
    "# print('total_time',total_time)\n",
    "# print('epoch_time',epoch_time)\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "list_datasets = ['ZINC','MNIST','CIFAR10','SBM_PATTERN','SBM_CLUSTER','TSP','COLLAB','CSL']\n",
    "#print('list_datasets',list_datasets)\n",
    "\n",
    "list_gnns = ['MLP','GCN','GraphSage','GatedGCN','GAT','MoNet','GIN','3WLGNN','RingGNN']\n",
    "#print('list_gnns',list_gnns)\n",
    "\n",
    "\n",
    "#list_datasets = ['SBM_CLUSTER']\n",
    "for data in list_datasets:\n",
    "    #print(data)\n",
    "    \n",
    "    for gnn in list_gnns:\n",
    "        #print('gnn:',gnn)\n",
    "        \n",
    "        acc_test_one_gnn = []\n",
    "        acc_train_one_gnn = []\n",
    "        convergence_one_gnn = []\n",
    "        total_time_one_gnn = []\n",
    "        epoch_time_one_gnn = []\n",
    "        nb_seeds = 0\n",
    "            \n",
    "        for i in range(len(file)):\n",
    "            \n",
    "            if data==dataset[i] and gnn==model[i]:\n",
    "                params_one_gnn = params[i]\n",
    "                acc_test_one_gnn.append(acc_test[i])\n",
    "                acc_train_one_gnn.append(acc_train[i])\n",
    "                convergence_one_gnn.append(convergence[i])\n",
    "                total_time_one_gnn.append(total_time[i])\n",
    "                epoch_time_one_gnn.append(epoch_time[i])\n",
    "                L = layer[i]\n",
    "                nb_seeds = nb_seeds + 1\n",
    "                \n",
    "                \n",
    "        \n",
    "        if len(acc_test_one_gnn)>0:\n",
    "            latex_str = f\"{data} & {nb_seeds} & {gnn} & {L} & {params_one_gnn} & {np.mean(acc_test_one_gnn):.3f}$\\pm${np.std(acc_test_one_gnn):.3f} & {np.mean(acc_train_one_gnn):.3f}$\\pm${np.std(acc_train_one_gnn):.3f} & {np.mean(convergence_one_gnn):.2f} & {np.mean(epoch_time_one_gnn):.2f}s/{np.mean(total_time_one_gnn):.2f}hr\"\n",
    "            print(\"\\nDataset & #Seeds & Model & L & Param & Acc_test & Acc_train & Speed & Epoch/Time\\n{}\".format(latex_str,nb_seeds))\n",
    "\n",
    "        \n",
    "\n",
    "print(\"\\n\")\n",
    "\n",
    "          "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
